// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GetSensorInfoTest.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Hardware.EV4.UnitTests
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Test.Robotics.Hardware.DAC;
    
    /// <summary>
    /// Test the GetSensorInfo class
    /// </summary>
    [TestClass]
    public class GetSensorInfoTest
    {
        /// <summary>
        /// Test SendGetSensorInfo.SendGetSensorInfo
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void GetSensorInfoContructorTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);
        }

        /// <summary>
        /// Test SendGetSensorInfo.Cancel
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(NotImplementedException), "An unhandled method call was allowed.")]
        public void GetSensorInfoCancelTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);

            sensorInfo.Cancel();
        }

        /// <summary>
        /// Test SendGetSensorInfo.CloseRequest
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void GetSensorInfoCloseRequestTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);

            sensorInfo.CloseRequest(true);
        }

        /// <summary>
        /// Test SendGetSensorInfo.ParseParameters
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void GetSensorInfoParseParametersTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);
            int mockDataSize = 128;
            byte[] readStuff = sensorInfo.ParseParameters(new MockReader(mockDataSize));

            Assert.IsTrue(
                readStuff.Length == mockDataSize, 
                string.Format(
                    "Parse Parameters returned an incorrect length byte array.  Should be 128 bytes, but was {0}", 
                    readStuff.Length));
        }

        /// <summary>
        /// Test SendGetSensorInfo.ParseResponse
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(NotImplementedException), "An unhandled method call was allowed.")]
        public void GetSensorInfoParseResponseTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);
            int mockDataSize = 128;

            sensorInfo.ParseResponse(new MockReader(mockDataSize));
        }

        /// <summary>
        /// Test SendGetSensorInfo.SendGetSensorInfo
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void GetSensorInfoPrepareRequestTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);

            Assert.IsTrue(sensorInfo.PrepareRequest(), "ParseResponse returned false");
        }

        /// <summary>
        /// Test SendGetSensorInfo.WriteParameters
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void GetSensorInfoWriteRequestTest()
        {
            GetSensorInfo sensorInfo = new GetSensorInfo();
            Assert.IsNotNull(sensorInfo);

            sensorInfo.WriteRequest(new MockWriter());
        }
    }
}
